package com.allen.workflow.listener.execution;

import com.allen.workflow.WfLogUtils;
import com.allen.workflow.delegate.BusinessExecution;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.ExecutionListener;

/**
 * @program: spring-boot-demo
 * @className BusinessExecutionListener
 * @description: 业务封装执行器监听器
 * @author: zp
 * @create: 2024-08-16 14:53
 * @Version 1.0
 **/
public abstract class BusinessExecutionListener implements ExecutionListener {

    @Override
    public void notify(DelegateExecution delegateExecution)
    {
        BusinessExecution businessExecution = new BusinessExecution(delegateExecution);
        onEvent(businessExecution);
    }


    protected  void onEvent(BusinessExecution delegateExecution){
        String eventName = delegateExecution.getEventName();
        switch (eventName) {
            case ExecutionListener.EVENTNAME_START:
                onStart(delegateExecution);
                break;
            case ExecutionListener.EVENTNAME_END:
                onEnd(delegateExecution);
                break;
            case ExecutionListener.EVENTNAME_TAKE:
                onTake(delegateExecution);
                break;
            default:
                break;
        }
    }


    protected abstract void onStart(BusinessExecution delegateExecution);

    protected abstract void onEnd(BusinessExecution delegateExecution);

    protected abstract void onTake(BusinessExecution delegateExecution);


}
